package org.vectrics.recruiter.user;

import org.vectrics.SystemException;
import org.vectrics.hibernate.Filter;
import org.vectrics.user.PersonSearchCriteria;
import org.vectrics.user.PersonSearcher;

public class RecruitPersonSearcher extends PersonSearcher {

	public Filter getFilterForCriteria(PersonSearchCriteria criteria, boolean ordered) {
		if ((criteria instanceof RecruitPersonSearchCriteria) == false) {
			throw new SystemException("CandidateSearcher needs to be passed a criteria that is of the type CandidateSearchCriteria");
		}

		RecruitPersonSearchCriteria recruitCriteria = (RecruitPersonSearchCriteria)criteria;
		Filter filter = super.getFilterForCriteria(criteria, ordered);
		if (recruitCriteria.getSourcesOnly()) {
			filter.addFrom("JobCandidate", "jobCandidate");
			filter.addCondition("jobCandidate.source.id=person.id");
		} else if (recruitCriteria.getCandidatesOnly()) {
			filter.addFrom("CandidateInfo", "candidateInfo");
			filter.addCondition("candidateInfo.person.id=person.id");
		}
		return(filter);
	}

	
}
